import { fetchApiListById,slotList} from '@/services/basiccapacity';
import { fetchSlotDetailBySlotId,knowledgeClassification,saveQA,getKnowledgeDetail ,getQAJsonAnswers,getAlikeQuestionList,knowledcombine,getStandardQuestion,getQAHistories,getQaIdByRequest} from '@/services/knowledgemanagement';
import {fakeAnswerRelevanceData} from '@/services/datastatistics';
import {  fetchApiDetailById} from '@/services/basiccapacity';

export default {
  namespace: 'editQa',
  state: {
    total: null,
    items: [],
    loading: false
  },

  effects: {
    *fetchApi({payload,callback}, { call, put }) {
      const response = yield call(fetchApiListById,payload);
      if (callback && typeof callback === 'function') {
        callback(response);
      }
      yield put({
        type: 'save',
        payload: response,
      });
    },
    *fetchSlot({payload,callback}, { call, put }) {
      const response = yield call(slotList,payload);
      if (callback && typeof callback === 'function') {
        callback(response);
      }
      yield put({
        type: 'save',
        payload: response,
      });
    },
    *getDictItemFromSlotId({payload,callback}, { call, put }) {
      const response = yield call(fetchSlotDetailBySlotId,payload);
      if (callback && typeof callback === 'function') {
        callback(response);
      }
      yield put({
        type: 'save',
        payload: response,
      });
    },
    *categoryListJson({payload,callback}, { call, put }) {
      const response = yield call(knowledgeClassification,payload);
      if (callback && typeof callback === 'function') {
        callback(response);
      }
      yield put({
        type: 'save',
        payload: response,
      });
    },
    *linkBoxJson({payload,callback}, { call, put }) {
      const response = yield call(fakeAnswerRelevanceData,payload);
      if (callback && typeof callback === 'function') {
        callback(response);
      }
      yield put({
        type: 'save',
        payload: response,
      });
    },
    *saveKp({payload,callback}, { call, put }) {
      const response = yield call(saveQA,payload);
      if (callback && typeof callback === 'function') {
        callback(response);
      }
      yield put({
        type: 'save',
        payload: response,
      });
    },
    *getDetailByQaid({payload,callback}, { call, put }) {
      const response = yield call(getKnowledgeDetail,payload);
      if (callback && typeof callback === 'function') {
        callback(response);
      }
      yield put({
        type: 'save',
        payload: response,
      });
    },
    *getJsonAnswerByQaId({payload,callback}, { call, put }) {
      const response = yield call(getQAJsonAnswers,payload);
      if (callback && typeof callback === 'function') {
        callback(response);
      }
      yield put({
        type: 'save',
        payload: response,
      });
    },
    *getQuestionsByQaId({payload,callback}, { call, put }) {
      const response = yield call(getAlikeQuestionList,payload);
      if (callback && typeof callback === 'function') {
        callback(response);
      }
      yield put({
        type: 'save',
        payload: response,
      });
    },
    *getStandardQuestionByQaId({payload,callback}, { call, put }) {
      const response = yield call(getStandardQuestion,payload);
      if (callback && typeof callback === 'function') {
        callback(response);
      }
      yield put({
        type: 'save',
        payload: response,
      });
    },
    *fetchApiDetailById({payload,callback}, { call, put }) {
      const response = yield call(fetchApiDetailById,payload);
      if (callback && typeof callback === 'function') {
        callback(response);
      }
      yield put({
        type: 'save',
        payload: response,
      });
    },
    *fetchQaFixHistoryByQaId({payload,callback}, { call, put }) {
      const response = yield call(getQAHistories,payload);
      if (callback && typeof callback === 'function') {
        callback(response);
      }
      yield put({
        type: 'save',
        payload: response,
      });
    },
    *getQaId({payload,callback}, { call, put }) {
      const response = yield call(getQaIdByRequest,payload);
      if (callback && typeof callback === 'function') {
        callback(response);
      }
      yield put({
        type: 'save',
        payload: response,
      });
    },
  },

  reducers: {
    save(state, { payload }) {
      return {
        ...state,
        ...payload,
      };
    }
  }
};
